package com.lbt.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lbt.commonuntils.R;
import com.lbt.eduservice.entity.EduCourse;
import com.lbt.eduservice.entity.EduTeacher;
import com.lbt.eduservice.service.EduCourseService;
import com.lbt.eduservice.service.EduTeacherService;
import com.lbt.servicebase.exceptionhandler.GuliException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(description = "讲师前台管理")
//@CrossOrigin
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {
    @Autowired
    EduTeacherService teacherService;
    @Autowired
    EduCourseService courseService;

    @ApiOperation("讲师分页查询")
    @PostMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeacher(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher>teacherPage=new Page<>(page,limit);
        Map<String,Object> map = teacherService.getFrontTeacherpage(teacherPage);
        return R.ok().data(map);
    }
    //讲师详情
    @ApiOperation("讲师详情getTeacherFrontList")
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacher(@PathVariable String teacherId){
        if(StringUtils.isBlank(teacherId)||!StringUtils.isNumeric(teacherId)){
            throw new GuliException(20001,"输入的值不正确");
        }
        //讲师基本信息
        EduTeacher byId = teacherService.getById(teacherId);
        //讲师所讲课程的基本信息
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);

        return R.ok().data("teacher",byId).data("courseList",courseList);

    }

}
